package com.gewu.pm.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.FunctionItemBean;

/**
 * 首页常用功能适配器
 */
public final class HomeFunctionAdapter extends AppAdapter<FunctionItemBean> {

    public HomeFunctionAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new FunctionHolder();
    }

    private final class FunctionHolder extends AppAdapter<?>.ViewHolder {

        private final ImageView ivFunctionIcon;
        private final TextView tvFunctionName;

        private FunctionHolder() {
            super(R.layout.home_function_item);
            ivFunctionIcon = findViewById(R.id.iv_function_icon);
            tvFunctionName = findViewById(R.id.tv_function_name);
        }

        @Override
        public void onBindView(int position) {
            FunctionItemBean item = getItem(position);
            ivFunctionIcon.setImageResource(item.getIconRes());
            tvFunctionName.setText(item.getName());
        }
    }
}

